{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "np.set_printoptions(precision=2)\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "from scipy import stats\n",
    "from collections import Counter\n",
    "\n",
    "sns.set_style('ticks')\n",
    "\n",
    "%matplotlib inline\n",
    "import warnings\n",
    "warnings.filterwarnings('ignore')\n",
    "import matplotlib as mpl\n",
    "mpl.rcParams['figure.dpi']= 300\n",
    "mpl.rc(\"savefig\", dpi=300)\n",
    "\n",
    "from scipy.special import xlogy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### Read files and select drugs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [],
   "source": [
    "# log2_median_ic50, log2_median_ic50_9f, log2_median_ic50_hn, log2_median_ic50_9f_hn, log2_median_ic50_3f_hn, log2_max_conc\n",
    "ref_type = 'log2_median_ic50_hn' # log2_median_ic50_3f_hn | log2_median_ic50_hn\n",
    "model_name = 'hn_drug_cw_dw10_100000_model' # hn_drug_cw_dw10_100000_model | hn_drug_cw_dw1_100000_model | hn_drug_cw_dwsim10_100000_model\n",
    "\n",
    "dosage_shifted = False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [],
   "source": [
    "norm_type = 'TPM'\n",
    "\n",
    "current_dir = '../result/HN_model/{}/'.format(norm_type)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Drug Name</th>\n",
       "      <th>Synonyms</th>\n",
       "      <th>Target</th>\n",
       "      <th>Target Pathway</th>\n",
       "      <th>Selleckchem Cat#</th>\n",
       "      <th>CAS number</th>\n",
       "      <th>PubCHEM</th>\n",
       "      <th>Others</th>\n",
       "      <th>entropy</th>\n",
       "      <th>max_conc</th>\n",
       "      <th>...</th>\n",
       "      <th>median_ic50_9f</th>\n",
       "      <th>log2_median_ic50_9f</th>\n",
       "      <th>log2_median_ic50_hn</th>\n",
       "      <th>median_ic50_hn</th>\n",
       "      <th>median_ic50_3f_hn</th>\n",
       "      <th>log2_median_ic50_3f_hn</th>\n",
       "      <th>median_ic50_9f_hn</th>\n",
       "      <th>log2_median_ic50_9f_hn</th>\n",
       "      <th>num_sensitive</th>\n",
       "      <th>num_sensitive_hn</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Drug ID</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1001</th>\n",
       "      <td>AICA Ribonucleotide</td>\n",
       "      <td>AICAR, N1-(b-D-Ribofuranosyl)-5-aminoimidazole...</td>\n",
       "      <td>AMPK agonist</td>\n",
       "      <td>Metabolism</td>\n",
       "      <td>S1802</td>\n",
       "      <td>2627-69-2</td>\n",
       "      <td>65110</td>\n",
       "      <td>NaN</td>\n",
       "      <td>6.034272</td>\n",
       "      <td>2000.0000</td>\n",
       "      <td>...</td>\n",
       "      <td>206.748380</td>\n",
       "      <td>7.691732</td>\n",
       "      <td>9.939784</td>\n",
       "      <td>982.139588</td>\n",
       "      <td>327.379863</td>\n",
       "      <td>8.354822</td>\n",
       "      <td>109.126621</td>\n",
       "      <td>6.769859</td>\n",
       "      <td>476</td>\n",
       "      <td>27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1003</th>\n",
       "      <td>Camptothecin</td>\n",
       "      <td>7-Ethyl-10-Hydroxy-Camptothecin, SN-38, Irinot...</td>\n",
       "      <td>TOP1</td>\n",
       "      <td>DNA replication</td>\n",
       "      <td>S1288</td>\n",
       "      <td>7689-03-4</td>\n",
       "      <td>104842</td>\n",
       "      <td>(SN-38, S4908, 86639-52-3) (Irinotecan, S1198,...</td>\n",
       "      <td>4.609530</td>\n",
       "      <td>0.1000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.002003</td>\n",
       "      <td>-8.963413</td>\n",
       "      <td>-7.587491</td>\n",
       "      <td>0.005199</td>\n",
       "      <td>0.001733</td>\n",
       "      <td>-9.172454</td>\n",
       "      <td>0.000578</td>\n",
       "      <td>-10.757416</td>\n",
       "      <td>688</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1004</th>\n",
       "      <td>Vinblastine</td>\n",
       "      <td>Velban</td>\n",
       "      <td>Microtubule destabiliser</td>\n",
       "      <td>Mitosis</td>\n",
       "      <td>S1248</td>\n",
       "      <td>143-67-9</td>\n",
       "      <td>6710780</td>\n",
       "      <td>NaN</td>\n",
       "      <td>4.297122</td>\n",
       "      <td>0.1000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.001599</td>\n",
       "      <td>-9.289051</td>\n",
       "      <td>-7.150982</td>\n",
       "      <td>0.007036</td>\n",
       "      <td>0.002345</td>\n",
       "      <td>-8.735945</td>\n",
       "      <td>0.000782</td>\n",
       "      <td>-10.320907</td>\n",
       "      <td>753</td>\n",
       "      <td>33</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1006</th>\n",
       "      <td>Cytarabine</td>\n",
       "      <td>Ara-Cytidine, Arabinosyl Cytosine, U-19920</td>\n",
       "      <td>Antimetabolite</td>\n",
       "      <td>DNA replication</td>\n",
       "      <td>S1648</td>\n",
       "      <td>147-94-4</td>\n",
       "      <td>6253</td>\n",
       "      <td>NaN</td>\n",
       "      <td>6.646594</td>\n",
       "      <td>2.0000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.163032</td>\n",
       "      <td>-2.616771</td>\n",
       "      <td>-1.342632</td>\n",
       "      <td>0.394301</td>\n",
       "      <td>0.131434</td>\n",
       "      <td>-2.927594</td>\n",
       "      <td>0.043811</td>\n",
       "      <td>-4.512557</td>\n",
       "      <td>508</td>\n",
       "      <td>25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1007</th>\n",
       "      <td>Docetaxel</td>\n",
       "      <td>RP-56976, Taxotere</td>\n",
       "      <td>Microtubule stabiliser</td>\n",
       "      <td>Mitosis</td>\n",
       "      <td>S1148</td>\n",
       "      <td>114977-28-5</td>\n",
       "      <td>148124</td>\n",
       "      <td>NaN</td>\n",
       "      <td>4.220984</td>\n",
       "      <td>0.0125</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000761</td>\n",
       "      <td>-10.358915</td>\n",
       "      <td>-9.792998</td>\n",
       "      <td>0.001127</td>\n",
       "      <td>0.000376</td>\n",
       "      <td>-11.377960</td>\n",
       "      <td>0.000125</td>\n",
       "      <td>-12.962923</td>\n",
       "      <td>584</td>\n",
       "      <td>32</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 27 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                   Drug Name  \\\n",
       "Drug ID                        \n",
       "1001     AICA Ribonucleotide   \n",
       "1003            Camptothecin   \n",
       "1004             Vinblastine   \n",
       "1006              Cytarabine   \n",
       "1007               Docetaxel   \n",
       "\n",
       "                                                  Synonyms  \\\n",
       "Drug ID                                                      \n",
       "1001     AICAR, N1-(b-D-Ribofuranosyl)-5-aminoimidazole...   \n",
       "1003     7-Ethyl-10-Hydroxy-Camptothecin, SN-38, Irinot...   \n",
       "1004                                                Velban   \n",
       "1006            Ara-Cytidine, Arabinosyl Cytosine, U-19920   \n",
       "1007                                    RP-56976, Taxotere   \n",
       "\n",
       "                           Target   Target Pathway Selleckchem Cat#  \\\n",
       "Drug ID                                                               \n",
       "1001                 AMPK agonist       Metabolism            S1802   \n",
       "1003                         TOP1  DNA replication            S1288   \n",
       "1004     Microtubule destabiliser          Mitosis            S1248   \n",
       "1006               Antimetabolite  DNA replication            S1648   \n",
       "1007       Microtubule stabiliser          Mitosis            S1148   \n",
       "\n",
       "          CAS number  PubCHEM  \\\n",
       "Drug ID                         \n",
       "1001       2627-69-2    65110   \n",
       "1003       7689-03-4   104842   \n",
       "1004        143-67-9  6710780   \n",
       "1006        147-94-4     6253   \n",
       "1007     114977-28-5   148124   \n",
       "\n",
       "                                                    Others   entropy  \\\n",
       "Drug ID                                                                \n",
       "1001                                                   NaN  6.034272   \n",
       "1003     (SN-38, S4908, 86639-52-3) (Irinotecan, S1198,...  4.609530   \n",
       "1004                                                   NaN  4.297122   \n",
       "1006                                                   NaN  6.646594   \n",
       "1007                                                   NaN  4.220984   \n",
       "\n",
       "          max_conc  ...  median_ic50_9f  log2_median_ic50_9f  \\\n",
       "Drug ID             ...                                        \n",
       "1001     2000.0000  ...      206.748380             7.691732   \n",
       "1003        0.1000  ...        0.002003            -8.963413   \n",
       "1004        0.1000  ...        0.001599            -9.289051   \n",
       "1006        2.0000  ...        0.163032            -2.616771   \n",
       "1007        0.0125  ...        0.000761           -10.358915   \n",
       "\n",
       "         log2_median_ic50_hn  median_ic50_hn  median_ic50_3f_hn  \\\n",
       "Drug ID                                                           \n",
       "1001                9.939784      982.139588         327.379863   \n",
       "1003               -7.587491        0.005199           0.001733   \n",
       "1004               -7.150982        0.007036           0.002345   \n",
       "1006               -1.342632        0.394301           0.131434   \n",
       "1007               -9.792998        0.001127           0.000376   \n",
       "\n",
       "         log2_median_ic50_3f_hn  median_ic50_9f_hn  log2_median_ic50_9f_hn  \\\n",
       "Drug ID                                                                      \n",
       "1001                   8.354822         109.126621                6.769859   \n",
       "1003                  -9.172454           0.000578              -10.757416   \n",
       "1004                  -8.735945           0.000782              -10.320907   \n",
       "1006                  -2.927594           0.043811               -4.512557   \n",
       "1007                 -11.377960           0.000125              -12.962923   \n",
       "\n",
       "         num_sensitive  num_sensitive_hn  \n",
       "Drug ID                                   \n",
       "1001               476                27  \n",
       "1003               688                30  \n",
       "1004               753                33  \n",
       "1006               508                25  \n",
       "1007               584                32  \n",
       "\n",
       "[5 rows x 27 columns]"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "drug_info_df = pd.read_csv('../preprocessed_data/GDSC/hn_drug_stat.csv', index_col=0)\n",
    "drug_info_df.index = drug_info_df.index.astype(str)\n",
    "\n",
    "drug_id_name_dict = dict(zip(drug_info_df.index, drug_info_df['Drug Name'].values))\n",
    "\n",
    "drug_info_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Afatinib',\n",
       " 'Docetaxel',\n",
       " 'Doxorubicin',\n",
       " 'Epothilone B',\n",
       " 'Gefitinib',\n",
       " 'Obatoclax Mesylate',\n",
       " 'PHA-793887',\n",
       " 'PI-103',\n",
       " 'Vorinostat']"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tested_drug_list = [1032, 1007, 133, 201, 1010] + [182, 301, 302] + [1012]\n",
    "[drug_id_name_dict[str(d)] for d in tested_drug_list]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>patient</th>\n",
       "      <th>drug_id</th>\n",
       "      <th>cluster</th>\n",
       "      <th>cluster_p</th>\n",
       "      <th>cluster_delta</th>\n",
       "      <th>delta</th>\n",
       "      <th>cluster_kill</th>\n",
       "      <th>kill</th>\n",
       "      <th>drug_name</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>HN120</td>\n",
       "      <td>1001</td>\n",
       "      <td>D1|D2|G1|G2</td>\n",
       "      <td>0.31318681318681|0.17582417582418|0.3406593406...</td>\n",
       "      <td>1.1490924101634|1.0228224713013|0.807486458736...</td>\n",
       "      <td>0.908454</td>\n",
       "      <td>31.07768069322|32.982724341963|36.361526571858...</td>\n",
       "      <td>32.378064</td>\n",
       "      <td>AICA Ribonucleotide</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>HN120</td>\n",
       "      <td>1003</td>\n",
       "      <td>D1|D2|G1|G2</td>\n",
       "      <td>0.31318681318681|0.17582417582418|0.3406593406...</td>\n",
       "      <td>0.82259227449208|0.80678235428939|0.6355808967...</td>\n",
       "      <td>0.663980</td>\n",
       "      <td>36.119586501242|36.372820715572|39.16096594173...</td>\n",
       "      <td>36.265572</td>\n",
       "      <td>Camptothecin</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>HN120</td>\n",
       "      <td>1004</td>\n",
       "      <td>D1|D2|G1|G2</td>\n",
       "      <td>0.31318681318681|0.17582417582418|0.3406593406...</td>\n",
       "      <td>1.1329744265808|0.94920159776164|0.94811144743...</td>\n",
       "      <td>0.937689</td>\n",
       "      <td>31.317486231647|34.120332036415|34.13731950223...</td>\n",
       "      <td>31.906440</td>\n",
       "      <td>Vinblastine</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>HN120</td>\n",
       "      <td>1006</td>\n",
       "      <td>D1|D2|G1|G2</td>\n",
       "      <td>0.31318681318681|0.17582417582418|0.3406593406...</td>\n",
       "      <td>0.64345405665561|0.73736230277016|1.0642299051...</td>\n",
       "      <td>0.782631</td>\n",
       "      <td>39.031023104429|37.493555437562|32.35143074316...</td>\n",
       "      <td>34.372665</td>\n",
       "      <td>Cytarabine</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>HN120</td>\n",
       "      <td>1007</td>\n",
       "      <td>D1|D2|G1|G2</td>\n",
       "      <td>0.31318681318681|0.17582417582418|0.3406593406...</td>\n",
       "      <td>3.6652578613737|3.5146840869921|4.191433189523...</td>\n",
       "      <td>3.646273</td>\n",
       "      <td>7.3063024840794|8.0454082266986|5.189316535910...</td>\n",
       "      <td>6.310247</td>\n",
       "      <td>Docetaxel</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  patient drug_id      cluster  \\\n",
       "0   HN120    1001  D1|D2|G1|G2   \n",
       "1   HN120    1003  D1|D2|G1|G2   \n",
       "2   HN120    1004  D1|D2|G1|G2   \n",
       "3   HN120    1006  D1|D2|G1|G2   \n",
       "4   HN120    1007  D1|D2|G1|G2   \n",
       "\n",
       "                                           cluster_p  \\\n",
       "0  0.31318681318681|0.17582417582418|0.3406593406...   \n",
       "1  0.31318681318681|0.17582417582418|0.3406593406...   \n",
       "2  0.31318681318681|0.17582417582418|0.3406593406...   \n",
       "3  0.31318681318681|0.17582417582418|0.3406593406...   \n",
       "4  0.31318681318681|0.17582417582418|0.3406593406...   \n",
       "\n",
       "                                       cluster_delta     delta  \\\n",
       "0  1.1490924101634|1.0228224713013|0.807486458736...  0.908454   \n",
       "1  0.82259227449208|0.80678235428939|0.6355808967...  0.663980   \n",
       "2  1.1329744265808|0.94920159776164|0.94811144743...  0.937689   \n",
       "3  0.64345405665561|0.73736230277016|1.0642299051...  0.782631   \n",
       "4  3.6652578613737|3.5146840869921|4.191433189523...  3.646273   \n",
       "\n",
       "                                        cluster_kill       kill  \\\n",
       "0  31.07768069322|32.982724341963|36.361526571858...  32.378064   \n",
       "1  36.119586501242|36.372820715572|39.16096594173...  36.265572   \n",
       "2  31.317486231647|34.120332036415|34.13731950223...  31.906440   \n",
       "3  39.031023104429|37.493555437562|32.35143074316...  34.372665   \n",
       "4  7.3063024840794|8.0454082266986|5.189316535910...   6.310247   \n",
       "\n",
       "             drug_name  \n",
       "0  AICA Ribonucleotide  \n",
       "1         Camptothecin  \n",
       "2          Vinblastine  \n",
       "3           Cytarabine  \n",
       "4            Docetaxel  "
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "if dosage_shifted:\n",
    "    single_drug_pred_df = pd.read_csv(current_dir + 'pred_drug_kill_{}_{}_shifted.csv'.format(ref_type, model_name))\n",
    "else:\n",
    "    single_drug_pred_df = pd.read_csv(current_dir + 'pred_drug_kill_{}_{}.csv'.format(ref_type, model_name))\n",
    "\n",
    "\n",
    "single_drug_pred_df.loc[:, 'drug_id'] = single_drug_pred_df.loc[:, 'drug_id'].values.astype(str)\n",
    "single_drug_pred_df.loc[:, 'drug_name'] = [drug_id_name_dict[d] for d in single_drug_pred_df.loc[:, 'drug_id'].values]\n",
    "\n",
    "patient_list = sorted(list(set(single_drug_pred_df['patient'])))\n",
    "# sel_drug_id_list = sorted(list(set(single_drug_pred_df['drug_id'])))\n",
    "\n",
    "single_drug_pred_df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### List all drug pairs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(216, 3)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>patient</th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>HN120</td>\n",
       "      <td>1032</td>\n",
       "      <td>1007</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>HN120</td>\n",
       "      <td>1032</td>\n",
       "      <td>133</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>HN120</td>\n",
       "      <td>1032</td>\n",
       "      <td>201</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>HN120</td>\n",
       "      <td>1032</td>\n",
       "      <td>1010</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>HN120</td>\n",
       "      <td>1032</td>\n",
       "      <td>182</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  patient     A     B\n",
       "0   HN120  1032  1007\n",
       "1   HN120  1032   133\n",
       "2   HN120  1032   201\n",
       "3   HN120  1032  1010\n",
       "4   HN120  1032   182"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "drug_combi_list = []\n",
    "n_drugs = len(tested_drug_list)\n",
    "\n",
    "for p in patient_list:\n",
    "    for x in range(0, n_drugs-1):\n",
    "        for y in range(x+1, n_drugs):\n",
    "            drug_x = str(tested_drug_list[x])\n",
    "            drug_y = str(tested_drug_list[y])\n",
    "\n",
    "            drug_combi_list += [[p, drug_x, drug_y]]\n",
    "\n",
    "drug_combi_df = pd.DataFrame(drug_combi_list, columns=['patient', 'A', 'B'])\n",
    "\n",
    "print (drug_combi_df.shape)\n",
    "drug_combi_df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### Get pred and info for each drug"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [],
   "source": [
    "merge_df = pd.merge(drug_combi_df, single_drug_pred_df, how='left', left_on=['patient', 'A'], right_on=['patient', 'drug_id'])\n",
    "drug_combi_pred_df = pd.merge(merge_df, single_drug_pred_df[['patient', 'drug_id', 'drug_name', 'cluster_delta', 'delta', 'cluster_kill', 'kill']], how='left', left_on=['patient', 'B'], right_on=['patient', 'drug_id'], suffixes=['_A', '_B'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>patient</th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>drug_id_A</th>\n",
       "      <th>cluster</th>\n",
       "      <th>cluster_p</th>\n",
       "      <th>cluster_delta_A</th>\n",
       "      <th>delta_A</th>\n",
       "      <th>cluster_kill_A</th>\n",
       "      <th>kill_A</th>\n",
       "      <th>drug_name_A</th>\n",
       "      <th>drug_id_B</th>\n",
       "      <th>drug_name_B</th>\n",
       "      <th>cluster_delta_B</th>\n",
       "      <th>delta_B</th>\n",
       "      <th>cluster_kill_B</th>\n",
       "      <th>kill_B</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>HN120</td>\n",
       "      <td>1032</td>\n",
       "      <td>1007</td>\n",
       "      <td>1032</td>\n",
       "      <td>D1|D2|G1|G2</td>\n",
       "      <td>0.31318681318681|0.17582417582418|0.3406593406...</td>\n",
       "      <td>2.0967882398606|2.0929630691675|2.078164480668...</td>\n",
       "      <td>1.980695</td>\n",
       "      <td>18.948148697871|18.988902061161|19.14719808199...</td>\n",
       "      <td>18.144044</td>\n",
       "      <td>Afatinib</td>\n",
       "      <td>1007</td>\n",
       "      <td>Docetaxel</td>\n",
       "      <td>3.6652578613737|3.5146840869921|4.191433189523...</td>\n",
       "      <td>3.646273</td>\n",
       "      <td>7.3063024840794|8.0454082266986|5.189316535910...</td>\n",
       "      <td>6.310247</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>HN120</td>\n",
       "      <td>1032</td>\n",
       "      <td>133</td>\n",
       "      <td>1032</td>\n",
       "      <td>D1|D2|G1|G2</td>\n",
       "      <td>0.31318681318681|0.17582417582418|0.3406593406...</td>\n",
       "      <td>2.0967882398606|2.0929630691675|2.078164480668...</td>\n",
       "      <td>1.980695</td>\n",
       "      <td>18.948148697871|18.988902061161|19.14719808199...</td>\n",
       "      <td>18.144044</td>\n",
       "      <td>Afatinib</td>\n",
       "      <td>133</td>\n",
       "      <td>Doxorubicin</td>\n",
       "      <td>-2.2488107673639|-1.5744259519154|-0.701068604...</td>\n",
       "      <td>-1.362472</td>\n",
       "      <td>82.617489566863|74.862811767297|61.91504134721...</td>\n",
       "      <td>68.514219</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>HN120</td>\n",
       "      <td>1032</td>\n",
       "      <td>201</td>\n",
       "      <td>1032</td>\n",
       "      <td>D1|D2|G1|G2</td>\n",
       "      <td>0.31318681318681|0.17582417582418|0.3406593406...</td>\n",
       "      <td>2.0967882398606|2.0929630691675|2.078164480668...</td>\n",
       "      <td>1.980695</td>\n",
       "      <td>18.948148697871|18.988902061161|19.14719808199...</td>\n",
       "      <td>18.144044</td>\n",
       "      <td>Afatinib</td>\n",
       "      <td>201</td>\n",
       "      <td>Epothilone B</td>\n",
       "      <td>-1.1345482908374|-0.50348795527066|1.789914949...</td>\n",
       "      <td>0.318228</td>\n",
       "      <td>68.705974268278|58.637293992614|22.43186009135...</td>\n",
       "      <td>43.029539</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>HN120</td>\n",
       "      <td>1032</td>\n",
       "      <td>1010</td>\n",
       "      <td>1032</td>\n",
       "      <td>D1|D2|G1|G2</td>\n",
       "      <td>0.31318681318681|0.17582417582418|0.3406593406...</td>\n",
       "      <td>2.0967882398606|2.0929630691675|2.078164480668...</td>\n",
       "      <td>1.980695</td>\n",
       "      <td>18.948148697871|18.988902061161|19.14719808199...</td>\n",
       "      <td>18.144044</td>\n",
       "      <td>Afatinib</td>\n",
       "      <td>1010</td>\n",
       "      <td>Gefitinib</td>\n",
       "      <td>1.6079293707945|1.607251437639|1.5826831158258...</td>\n",
       "      <td>1.511870</td>\n",
       "      <td>24.702700340069|24.711441876835|25.02963574733...</td>\n",
       "      <td>23.696096</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>HN120</td>\n",
       "      <td>1032</td>\n",
       "      <td>182</td>\n",
       "      <td>1032</td>\n",
       "      <td>D1|D2|G1|G2</td>\n",
       "      <td>0.31318681318681|0.17582417582418|0.3406593406...</td>\n",
       "      <td>2.0967882398606|2.0929630691675|2.078164480668...</td>\n",
       "      <td>1.980695</td>\n",
       "      <td>18.948148697871|18.988902061161|19.14719808199...</td>\n",
       "      <td>18.144044</td>\n",
       "      <td>Afatinib</td>\n",
       "      <td>182</td>\n",
       "      <td>Obatoclax Mesylate</td>\n",
       "      <td>-0.085939217579996|0.30168298492716|1.03796021...</td>\n",
       "      <td>0.453389</td>\n",
       "      <td>51.48877295384|44.791198983324|32.751208206546...</td>\n",
       "      <td>39.943988</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  patient     A     B drug_id_A      cluster  \\\n",
       "0   HN120  1032  1007      1032  D1|D2|G1|G2   \n",
       "1   HN120  1032   133      1032  D1|D2|G1|G2   \n",
       "2   HN120  1032   201      1032  D1|D2|G1|G2   \n",
       "3   HN120  1032  1010      1032  D1|D2|G1|G2   \n",
       "4   HN120  1032   182      1032  D1|D2|G1|G2   \n",
       "\n",
       "                                           cluster_p  \\\n",
       "0  0.31318681318681|0.17582417582418|0.3406593406...   \n",
       "1  0.31318681318681|0.17582417582418|0.3406593406...   \n",
       "2  0.31318681318681|0.17582417582418|0.3406593406...   \n",
       "3  0.31318681318681|0.17582417582418|0.3406593406...   \n",
       "4  0.31318681318681|0.17582417582418|0.3406593406...   \n",
       "\n",
       "                                     cluster_delta_A   delta_A  \\\n",
       "0  2.0967882398606|2.0929630691675|2.078164480668...  1.980695   \n",
       "1  2.0967882398606|2.0929630691675|2.078164480668...  1.980695   \n",
       "2  2.0967882398606|2.0929630691675|2.078164480668...  1.980695   \n",
       "3  2.0967882398606|2.0929630691675|2.078164480668...  1.980695   \n",
       "4  2.0967882398606|2.0929630691675|2.078164480668...  1.980695   \n",
       "\n",
       "                                      cluster_kill_A     kill_A drug_name_A  \\\n",
       "0  18.948148697871|18.988902061161|19.14719808199...  18.144044    Afatinib   \n",
       "1  18.948148697871|18.988902061161|19.14719808199...  18.144044    Afatinib   \n",
       "2  18.948148697871|18.988902061161|19.14719808199...  18.144044    Afatinib   \n",
       "3  18.948148697871|18.988902061161|19.14719808199...  18.144044    Afatinib   \n",
       "4  18.948148697871|18.988902061161|19.14719808199...  18.144044    Afatinib   \n",
       "\n",
       "  drug_id_B         drug_name_B  \\\n",
       "0      1007           Docetaxel   \n",
       "1       133         Doxorubicin   \n",
       "2       201        Epothilone B   \n",
       "3      1010           Gefitinib   \n",
       "4       182  Obatoclax Mesylate   \n",
       "\n",
       "                                     cluster_delta_B   delta_B  \\\n",
       "0  3.6652578613737|3.5146840869921|4.191433189523...  3.646273   \n",
       "1  -2.2488107673639|-1.5744259519154|-0.701068604... -1.362472   \n",
       "2  -1.1345482908374|-0.50348795527066|1.789914949...  0.318228   \n",
       "3  1.6079293707945|1.607251437639|1.5826831158258...  1.511870   \n",
       "4  -0.085939217579996|0.30168298492716|1.03796021...  0.453389   \n",
       "\n",
       "                                      cluster_kill_B     kill_B  \n",
       "0  7.3063024840794|8.0454082266986|5.189316535910...   6.310247  \n",
       "1  82.617489566863|74.862811767297|61.91504134721...  68.514219  \n",
       "2  68.705974268278|58.637293992614|22.43186009135...  43.029539  \n",
       "3  24.702700340069|24.711441876835|25.02963574733...  23.696096  \n",
       "4  51.48877295384|44.791198983324|32.751208206546...  39.943988  "
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "drug_combi_pred_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [],
   "source": [
    "rows = []\n",
    "for _, data in drug_combi_pred_df.iterrows():\n",
    "    \n",
    "    cluster_p = np.array([float(p) for p in data['cluster_p'].split('|')])\n",
    "    \n",
    "    cluster_kill_A = np.array([float(k) for k in data['cluster_kill_A'].split('|')])\n",
    "    cluster_kill_B = np.array([float(k) for k in data['cluster_kill_B'].split('|')])\n",
    "    \n",
    "    cluster_kill_C = cluster_kill_A + cluster_kill_B - np.multiply(cluster_kill_A/100, cluster_kill_B/100)*100\n",
    "    kill_C = np.sum(cluster_p * cluster_kill_C)\n",
    "    \n",
    "    best_kill = np.max([data['kill_A'], data['kill_B']])\n",
    "    improve = kill_C - best_kill\n",
    "    improve_p = (kill_C - best_kill) / best_kill\n",
    "    \n",
    "    ##### specificity (entropy) #####\n",
    "    \n",
    "    temp_A = np.sum(cluster_p[cluster_kill_A > cluster_kill_B])\n",
    "    temp_B = np.sum(cluster_p[cluster_kill_A <= cluster_kill_B])\n",
    "    if temp_A == 0 or temp_B == 0:\n",
    "        entropy = 0\n",
    "    else:\n",
    "        entropy = -(temp_A * np.log2(temp_A) + temp_B * np.log2(temp_B))\n",
    "    \n",
    "    sum_kill_dif = np.sum(np.abs(cluster_kill_A - cluster_kill_B))\n",
    "    \n",
    "    ##### save output #####\n",
    "    \n",
    "    rows += [['|'.join([\"{:.14}\".format(k) for k in cluster_kill_C])] + [kill_C, improve, improve_p, entropy, sum_kill_dif]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>patient</th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>drug_id_A</th>\n",
       "      <th>cluster</th>\n",
       "      <th>cluster_p</th>\n",
       "      <th>cluster_delta_A</th>\n",
       "      <th>delta_A</th>\n",
       "      <th>cluster_kill_A</th>\n",
       "      <th>kill_A</th>\n",
       "      <th>...</th>\n",
       "      <th>cluster_delta_B</th>\n",
       "      <th>delta_B</th>\n",
       "      <th>cluster_kill_B</th>\n",
       "      <th>kill_B</th>\n",
       "      <th>cluster_kill_C</th>\n",
       "      <th>kill_C</th>\n",
       "      <th>improve</th>\n",
       "      <th>improve_p</th>\n",
       "      <th>kill_entropy</th>\n",
       "      <th>sum_kill_dif</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>HN120</td>\n",
       "      <td>1032</td>\n",
       "      <td>1007</td>\n",
       "      <td>1032</td>\n",
       "      <td>D1|D2|G1|G2</td>\n",
       "      <td>0.31318681318681|0.17582417582418|0.3406593406...</td>\n",
       "      <td>2.0967882398606|2.0929630691675|2.078164480668...</td>\n",
       "      <td>1.980695</td>\n",
       "      <td>18.948148697871|18.988902061161|19.14719808199...</td>\n",
       "      <td>18.144044</td>\n",
       "      <td>...</td>\n",
       "      <td>3.6652578613737|3.5146840869921|4.191433189523...</td>\n",
       "      <td>3.646273</td>\n",
       "      <td>7.3063024840794|8.0454082266986|5.189316535910...</td>\n",
       "      <td>6.310247</td>\n",
       "      <td>24.870042122951|25.506575599271|23.34290590166...</td>\n",
       "      <td>23.250498</td>\n",
       "      <td>5.106453</td>\n",
       "      <td>0.281440</td>\n",
       "      <td>0.0</td>\n",
       "      <td>49.024381</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>HN120</td>\n",
       "      <td>1032</td>\n",
       "      <td>133</td>\n",
       "      <td>1032</td>\n",
       "      <td>D1|D2|G1|G2</td>\n",
       "      <td>0.31318681318681|0.17582417582418|0.3406593406...</td>\n",
       "      <td>2.0967882398606|2.0929630691675|2.078164480668...</td>\n",
       "      <td>1.980695</td>\n",
       "      <td>18.948148697871|18.988902061161|19.14719808199...</td>\n",
       "      <td>18.144044</td>\n",
       "      <td>...</td>\n",
       "      <td>-2.2488107673639|-1.5744259519154|-0.701068604...</td>\n",
       "      <td>-1.362472</td>\n",
       "      <td>82.617489566863|74.862811767297|61.91504134721...</td>\n",
       "      <td>68.514219</td>\n",
       "      <td>85.911153491157|79.636087821735|69.20724381990...</td>\n",
       "      <td>73.588564</td>\n",
       "      <td>5.074345</td>\n",
       "      <td>0.074063</td>\n",
       "      <td>0.0</td>\n",
       "      <td>212.249633</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>HN120</td>\n",
       "      <td>1032</td>\n",
       "      <td>201</td>\n",
       "      <td>1032</td>\n",
       "      <td>D1|D2|G1|G2</td>\n",
       "      <td>0.31318681318681|0.17582417582418|0.3406593406...</td>\n",
       "      <td>2.0967882398606|2.0929630691675|2.078164480668...</td>\n",
       "      <td>1.980695</td>\n",
       "      <td>18.948148697871|18.988902061161|19.14719808199...</td>\n",
       "      <td>18.144044</td>\n",
       "      <td>...</td>\n",
       "      <td>-1.1345482908374|-0.50348795527066|1.789914949...</td>\n",
       "      <td>0.318228</td>\n",
       "      <td>68.705974268278|58.637293992614|22.43186009135...</td>\n",
       "      <td>43.029539</td>\n",
       "      <td>74.635612797475|66.491617726202|37.28398548817...</td>\n",
       "      <td>52.983812</td>\n",
       "      <td>9.954272</td>\n",
       "      <td>0.231336</td>\n",
       "      <td>0.0</td>\n",
       "      <td>102.716624</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>HN120</td>\n",
       "      <td>1032</td>\n",
       "      <td>1010</td>\n",
       "      <td>1032</td>\n",
       "      <td>D1|D2|G1|G2</td>\n",
       "      <td>0.31318681318681|0.17582417582418|0.3406593406...</td>\n",
       "      <td>2.0967882398606|2.0929630691675|2.078164480668...</td>\n",
       "      <td>1.980695</td>\n",
       "      <td>18.948148697871|18.988902061161|19.14719808199...</td>\n",
       "      <td>18.144044</td>\n",
       "      <td>...</td>\n",
       "      <td>1.6079293707945|1.607251437639|1.5826831158258...</td>\n",
       "      <td>1.511870</td>\n",
       "      <td>24.702700340069|24.711441876835|25.02963574733...</td>\n",
       "      <td>23.696096</td>\n",
       "      <td>38.970144645114|39.007912442103|39.38435989358...</td>\n",
       "      <td>37.316629</td>\n",
       "      <td>13.620534</td>\n",
       "      <td>0.574801</td>\n",
       "      <td>0.0</td>\n",
       "      <td>23.479140</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>HN120</td>\n",
       "      <td>1032</td>\n",
       "      <td>182</td>\n",
       "      <td>1032</td>\n",
       "      <td>D1|D2|G1|G2</td>\n",
       "      <td>0.31318681318681|0.17582417582418|0.3406593406...</td>\n",
       "      <td>2.0967882398606|2.0929630691675|2.078164480668...</td>\n",
       "      <td>1.980695</td>\n",
       "      <td>18.948148697871|18.988902061161|19.14719808199...</td>\n",
       "      <td>18.144044</td>\n",
       "      <td>...</td>\n",
       "      <td>-0.085939217579996|0.30168298492716|1.03796021...</td>\n",
       "      <td>0.453389</td>\n",
       "      <td>51.48877295384|44.791198983324|32.751208206546...</td>\n",
       "      <td>39.943988</td>\n",
       "      <td>60.680752389708|55.274744137522|45.62746757898...</td>\n",
       "      <td>50.471037</td>\n",
       "      <td>10.527049</td>\n",
       "      <td>0.263545</td>\n",
       "      <td>0.0</td>\n",
       "      <td>92.112932</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 23 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "  patient     A     B drug_id_A      cluster  \\\n",
       "0   HN120  1032  1007      1032  D1|D2|G1|G2   \n",
       "1   HN120  1032   133      1032  D1|D2|G1|G2   \n",
       "2   HN120  1032   201      1032  D1|D2|G1|G2   \n",
       "3   HN120  1032  1010      1032  D1|D2|G1|G2   \n",
       "4   HN120  1032   182      1032  D1|D2|G1|G2   \n",
       "\n",
       "                                           cluster_p  \\\n",
       "0  0.31318681318681|0.17582417582418|0.3406593406...   \n",
       "1  0.31318681318681|0.17582417582418|0.3406593406...   \n",
       "2  0.31318681318681|0.17582417582418|0.3406593406...   \n",
       "3  0.31318681318681|0.17582417582418|0.3406593406...   \n",
       "4  0.31318681318681|0.17582417582418|0.3406593406...   \n",
       "\n",
       "                                     cluster_delta_A   delta_A  \\\n",
       "0  2.0967882398606|2.0929630691675|2.078164480668...  1.980695   \n",
       "1  2.0967882398606|2.0929630691675|2.078164480668...  1.980695   \n",
       "2  2.0967882398606|2.0929630691675|2.078164480668...  1.980695   \n",
       "3  2.0967882398606|2.0929630691675|2.078164480668...  1.980695   \n",
       "4  2.0967882398606|2.0929630691675|2.078164480668...  1.980695   \n",
       "\n",
       "                                      cluster_kill_A     kill_A  ...  \\\n",
       "0  18.948148697871|18.988902061161|19.14719808199...  18.144044  ...   \n",
       "1  18.948148697871|18.988902061161|19.14719808199...  18.144044  ...   \n",
       "2  18.948148697871|18.988902061161|19.14719808199...  18.144044  ...   \n",
       "3  18.948148697871|18.988902061161|19.14719808199...  18.144044  ...   \n",
       "4  18.948148697871|18.988902061161|19.14719808199...  18.144044  ...   \n",
       "\n",
       "                                     cluster_delta_B   delta_B  \\\n",
       "0  3.6652578613737|3.5146840869921|4.191433189523...  3.646273   \n",
       "1  -2.2488107673639|-1.5744259519154|-0.701068604... -1.362472   \n",
       "2  -1.1345482908374|-0.50348795527066|1.789914949...  0.318228   \n",
       "3  1.6079293707945|1.607251437639|1.5826831158258...  1.511870   \n",
       "4  -0.085939217579996|0.30168298492716|1.03796021...  0.453389   \n",
       "\n",
       "                                      cluster_kill_B     kill_B  \\\n",
       "0  7.3063024840794|8.0454082266986|5.189316535910...   6.310247   \n",
       "1  82.617489566863|74.862811767297|61.91504134721...  68.514219   \n",
       "2  68.705974268278|58.637293992614|22.43186009135...  43.029539   \n",
       "3  24.702700340069|24.711441876835|25.02963574733...  23.696096   \n",
       "4  51.48877295384|44.791198983324|32.751208206546...  39.943988   \n",
       "\n",
       "                                      cluster_kill_C     kill_C    improve  \\\n",
       "0  24.870042122951|25.506575599271|23.34290590166...  23.250498   5.106453   \n",
       "1  85.911153491157|79.636087821735|69.20724381990...  73.588564   5.074345   \n",
       "2  74.635612797475|66.491617726202|37.28398548817...  52.983812   9.954272   \n",
       "3  38.970144645114|39.007912442103|39.38435989358...  37.316629  13.620534   \n",
       "4  60.680752389708|55.274744137522|45.62746757898...  50.471037  10.527049   \n",
       "\n",
       "  improve_p  kill_entropy  sum_kill_dif  \n",
       "0  0.281440           0.0     49.024381  \n",
       "1  0.074063           0.0    212.249633  \n",
       "2  0.231336           0.0    102.716624  \n",
       "3  0.574801           0.0     23.479140  \n",
       "4  0.263545           0.0     92.112932  \n",
       "\n",
       "[5 rows x 23 columns]"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "drug_combi_pred_df = pd.concat([drug_combi_pred_df, pd.DataFrame(rows, columns=['cluster_kill_C', 'kill_C', 'improve', 'improve_p', 'kill_entropy', 'sum_kill_dif'])], axis=1)\n",
    "drug_combi_pred_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>patient</th>\n",
       "      <th>drug_id_A</th>\n",
       "      <th>drug_name_A</th>\n",
       "      <th>drug_id_B</th>\n",
       "      <th>drug_name_B</th>\n",
       "      <th>cluster</th>\n",
       "      <th>cluster_p</th>\n",
       "      <th>cluster_kill_A</th>\n",
       "      <th>cluster_kill_B</th>\n",
       "      <th>cluster_kill_C</th>\n",
       "      <th>kill_A</th>\n",
       "      <th>kill_B</th>\n",
       "      <th>kill_C</th>\n",
       "      <th>improve</th>\n",
       "      <th>improve_p</th>\n",
       "      <th>kill_entropy</th>\n",
       "      <th>sum_kill_dif</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>HN120</td>\n",
       "      <td>1032</td>\n",
       "      <td>Afatinib</td>\n",
       "      <td>1007</td>\n",
       "      <td>Docetaxel</td>\n",
       "      <td>D1|D2|G1|G2</td>\n",
       "      <td>0.31318681318681|0.17582417582418|0.3406593406...</td>\n",
       "      <td>18.948148697871|18.988902061161|19.14719808199...</td>\n",
       "      <td>7.3063024840794|8.0454082266986|5.189316535910...</td>\n",
       "      <td>24.870042122951|25.506575599271|23.34290590166...</td>\n",
       "      <td>18.144044</td>\n",
       "      <td>6.310247</td>\n",
       "      <td>23.250498</td>\n",
       "      <td>5.106453</td>\n",
       "      <td>0.281440</td>\n",
       "      <td>0.0</td>\n",
       "      <td>49.024381</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>HN120</td>\n",
       "      <td>1032</td>\n",
       "      <td>Afatinib</td>\n",
       "      <td>133</td>\n",
       "      <td>Doxorubicin</td>\n",
       "      <td>D1|D2|G1|G2</td>\n",
       "      <td>0.31318681318681|0.17582417582418|0.3406593406...</td>\n",
       "      <td>18.948148697871|18.988902061161|19.14719808199...</td>\n",
       "      <td>82.617489566863|74.862811767297|61.91504134721...</td>\n",
       "      <td>85.911153491157|79.636087821735|69.20724381990...</td>\n",
       "      <td>18.144044</td>\n",
       "      <td>68.514219</td>\n",
       "      <td>73.588564</td>\n",
       "      <td>5.074345</td>\n",
       "      <td>0.074063</td>\n",
       "      <td>0.0</td>\n",
       "      <td>212.249633</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>HN120</td>\n",
       "      <td>1032</td>\n",
       "      <td>Afatinib</td>\n",
       "      <td>201</td>\n",
       "      <td>Epothilone B</td>\n",
       "      <td>D1|D2|G1|G2</td>\n",
       "      <td>0.31318681318681|0.17582417582418|0.3406593406...</td>\n",
       "      <td>18.948148697871|18.988902061161|19.14719808199...</td>\n",
       "      <td>68.705974268278|58.637293992614|22.43186009135...</td>\n",
       "      <td>74.635612797475|66.491617726202|37.28398548817...</td>\n",
       "      <td>18.144044</td>\n",
       "      <td>43.029539</td>\n",
       "      <td>52.983812</td>\n",
       "      <td>9.954272</td>\n",
       "      <td>0.231336</td>\n",
       "      <td>0.0</td>\n",
       "      <td>102.716624</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>HN120</td>\n",
       "      <td>1032</td>\n",
       "      <td>Afatinib</td>\n",
       "      <td>1010</td>\n",
       "      <td>Gefitinib</td>\n",
       "      <td>D1|D2|G1|G2</td>\n",
       "      <td>0.31318681318681|0.17582417582418|0.3406593406...</td>\n",
       "      <td>18.948148697871|18.988902061161|19.14719808199...</td>\n",
       "      <td>24.702700340069|24.711441876835|25.02963574733...</td>\n",
       "      <td>38.970144645114|39.007912442103|39.38435989358...</td>\n",
       "      <td>18.144044</td>\n",
       "      <td>23.696096</td>\n",
       "      <td>37.316629</td>\n",
       "      <td>13.620534</td>\n",
       "      <td>0.574801</td>\n",
       "      <td>0.0</td>\n",
       "      <td>23.479140</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>HN120</td>\n",
       "      <td>1032</td>\n",
       "      <td>Afatinib</td>\n",
       "      <td>182</td>\n",
       "      <td>Obatoclax Mesylate</td>\n",
       "      <td>D1|D2|G1|G2</td>\n",
       "      <td>0.31318681318681|0.17582417582418|0.3406593406...</td>\n",
       "      <td>18.948148697871|18.988902061161|19.14719808199...</td>\n",
       "      <td>51.48877295384|44.791198983324|32.751208206546...</td>\n",
       "      <td>60.680752389708|55.274744137522|45.62746757898...</td>\n",
       "      <td>18.144044</td>\n",
       "      <td>39.943988</td>\n",
       "      <td>50.471037</td>\n",
       "      <td>10.527049</td>\n",
       "      <td>0.263545</td>\n",
       "      <td>0.0</td>\n",
       "      <td>92.112932</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  patient drug_id_A drug_name_A drug_id_B         drug_name_B      cluster  \\\n",
       "0   HN120      1032    Afatinib      1007           Docetaxel  D1|D2|G1|G2   \n",
       "1   HN120      1032    Afatinib       133         Doxorubicin  D1|D2|G1|G2   \n",
       "2   HN120      1032    Afatinib       201        Epothilone B  D1|D2|G1|G2   \n",
       "3   HN120      1032    Afatinib      1010           Gefitinib  D1|D2|G1|G2   \n",
       "4   HN120      1032    Afatinib       182  Obatoclax Mesylate  D1|D2|G1|G2   \n",
       "\n",
       "                                           cluster_p  \\\n",
       "0  0.31318681318681|0.17582417582418|0.3406593406...   \n",
       "1  0.31318681318681|0.17582417582418|0.3406593406...   \n",
       "2  0.31318681318681|0.17582417582418|0.3406593406...   \n",
       "3  0.31318681318681|0.17582417582418|0.3406593406...   \n",
       "4  0.31318681318681|0.17582417582418|0.3406593406...   \n",
       "\n",
       "                                      cluster_kill_A  \\\n",
       "0  18.948148697871|18.988902061161|19.14719808199...   \n",
       "1  18.948148697871|18.988902061161|19.14719808199...   \n",
       "2  18.948148697871|18.988902061161|19.14719808199...   \n",
       "3  18.948148697871|18.988902061161|19.14719808199...   \n",
       "4  18.948148697871|18.988902061161|19.14719808199...   \n",
       "\n",
       "                                      cluster_kill_B  \\\n",
       "0  7.3063024840794|8.0454082266986|5.189316535910...   \n",
       "1  82.617489566863|74.862811767297|61.91504134721...   \n",
       "2  68.705974268278|58.637293992614|22.43186009135...   \n",
       "3  24.702700340069|24.711441876835|25.02963574733...   \n",
       "4  51.48877295384|44.791198983324|32.751208206546...   \n",
       "\n",
       "                                      cluster_kill_C     kill_A     kill_B  \\\n",
       "0  24.870042122951|25.506575599271|23.34290590166...  18.144044   6.310247   \n",
       "1  85.911153491157|79.636087821735|69.20724381990...  18.144044  68.514219   \n",
       "2  74.635612797475|66.491617726202|37.28398548817...  18.144044  43.029539   \n",
       "3  38.970144645114|39.007912442103|39.38435989358...  18.144044  23.696096   \n",
       "4  60.680752389708|55.274744137522|45.62746757898...  18.144044  39.943988   \n",
       "\n",
       "      kill_C    improve  improve_p  kill_entropy  sum_kill_dif  \n",
       "0  23.250498   5.106453   0.281440           0.0     49.024381  \n",
       "1  73.588564   5.074345   0.074063           0.0    212.249633  \n",
       "2  52.983812   9.954272   0.231336           0.0    102.716624  \n",
       "3  37.316629  13.620534   0.574801           0.0     23.479140  \n",
       "4  50.471037  10.527049   0.263545           0.0     92.112932  "
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "drug_combi_pred_df = drug_combi_pred_df[['patient', 'drug_id_A', 'drug_name_A', 'drug_id_B', 'drug_name_B', 'cluster', 'cluster_p', 'cluster_kill_A', 'cluster_kill_B', 'cluster_kill_C', 'kill_A', 'kill_B', 'kill_C', 'improve', 'improve_p', 'kill_entropy', 'sum_kill_dif']]\n",
    "\n",
    "drug_combi_pred_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [],
   "source": [
    "if dosage_shifted:\n",
    "    drug_combi_pred_df.to_csv(current_dir + 'pred_combi_kill_{}_{}_shifted.csv'.format(ref_type, model_name), index=False)\n",
    "else:\n",
    "    drug_combi_pred_df.to_csv(current_dir + 'pred_combi_kill_{}_{}.csv'.format(ref_type, model_name), index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
